home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 100754.2730@compuserve.com (Martin Aupperle)
- Newsgroups: comp.lang.c++
- Subject: Re: Is it OK to delete const *type pointers?
- Date: Thu, 11 Apr 1996 22:55:26 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4kk6fr$91g@dub-news-svc-3.compuserve.com>
- References: <4k9g7c$fl9@arl-news-svc-5.compuserve.com>
- NNTP-Posting-Host: hd68-145.compuserve.com
- X-Newsreader: Forte Free Agent v0.56
-
- Philippe Verdy <100105.3120@compuserve.com> wrote:
-
-
- >The following compiles under BC++ 4.0, 4.5, and 5.0:
- >int const *ptr = new int(1);
- >int const *arr = new int[10];
- >main()
- >{
- > delete ptr;
- > delete[] arr;
- >}
-
- >Being const does not mean the object is read-only. Nor does
- >it mean that its value won't change.
-
- That's exactly what it means.
-
- >It only forbids writing to it directly without an
- >explicit const_cast<>.
-
- What do you mean by "writing to it directly?" For my objects, I only
- can change members, and this is not allowed for const objects.
-
- >This cast however is an operator
- >which can be overriden to enforce const-ness, by returning
- >a non-const copy of the referenced object.
-
- This is EXACTLY what I do not want to happen. The intention of the
- programmer was to change a object, and if this is not possible, he/she
- should receive an error. Usually, if you have a pointer to a const
- object, you typically are within a function, and there are also non
- const pointers in the calling function one level higher. If you
- silently make a copy, the calling function still has the unchanged
- object, which was not intended by the design. This goes unnoticed and
- can only be determined at runtime.
-
- BTW, who is responsible for deleting your "temporary" object?
-
-
- -----------------------------------
- Signatures are a waste of bandwidth
- -----------------------------------
-
-